
<div class="layui-fluid">


    	<form class="layui-form layui-form-pane" action="" id="addFormA">
    	<input type="hidden" name="id" id="hiddenIdA" />
    	<input type="hidden" name="formId" id="formIdA"/>
    	<input type="hidden" name="groupId" value="compensation_pic">
    	<input type="hidden" name="optCounter" id="optCounterIdA" />
    	<div class="layui-form-item" style="margin-top:10px;">
    		<div class="layui-inline">
				      <label class="layui-form-label">选择平台</label>
				      <div class="layui-input-inline">
				        	 <select id="platformCombA" readonly="readonly" name="platformId" lay-verify="required" lay-search="">
							          <option value="">请选择平台</option>
							        </select>
				      </div>
			</div>
			
			<div class="layui-inline">
				      <label class="layui-form-label">供应商</label>
				      <div class="layui-input-inline">
		                     	<select id="supplierCombA" readonly="readonly" name="supplierId" lay-verify="required" lay-search="">
							         <option value="">请选择供应商</option>
							        </select>
				      </div>
			</div>
    	
    		<div class="layui-inline">
				      <label class="layui-form-label">订单号</label>
				      <div class="layui-input-inline">
				        	 <input id="orderNoIdA" name="orderNo" lay-verify="required" maxlength="50" class="layui-input" type="text" placeholder="输入订单号"/> 
				      </div>
			</div>
			
			<div class="layui-inline">
				      <label class="layui-form-label">赔付方式</label>
				      <div class="layui-input-inline">
				        	 <input id="outTypeIdA" name="outType" lay-verify="required" maxlength="20" class="layui-input" type="text" placeholder="输入赔付方式"/> 
				      </div>
			</div>
			
			<div class="layui-inline">
				      <label class="layui-form-label">打款账户</label>
				      <div class="layui-input-inline">
				        	 <input id="outAccountIdA" name="outAccount" lay-verify="required" maxlength="50" class="layui-input" type="text" placeholder="输入打款账户"/> 
				      </div>
			</div>
			
			
			<div class="layui-inline">
				      <label class="layui-form-label">赔付金额</label>
				      <div class="layui-input-inline">
				        	 <input id="outAmountIdA" name="outAmount" lay-verify="required|number" class="layui-input" type="text" placeholder="输入金额"/> 
				      </div>
			</div>
			
			
			
			<!-- 
			<div class="layui-inline">
				      <label class="layui-form-label">赔付人</label>
				      <div class="layui-input-inline">
				        	<input id="pfrId" name="outUser" lay-verify="required" readonly="readonly" required class="layui-input" type="text"  placeholder="赔付人"/>
		                     
				      </div>
			</div> -->
    		<div class="layui-form-item layui-form-text">
						  		<label class="layui-form-label">备注</label>
								    <div class="layui-input-block">
								      <textarea placeholder="请输入内容" name="reason" id="remarkIdA" maxlength="300" class="layui-textarea"></textarea>
								    </div>
				</div>
    		
    	
    	
             <div class="layui-upload">
	  			<button type="button" class="layui-btn" id="upload_picIdA">多图片上传</button> 
	  			<button type="button" class="layui-btn" id="cleanPicsA">清空图片</button> 
	  			<font color=red>* 注意</font>： 在导出的赔付列表的时候，只会导出第一张图片。
	  			<blockquote class="layui-elem-quote layui-quote-nm" style="margin-top: 10px;">
	    			<div class="layui-upload-list" id="upload_picsIdA" style="height: 70px;max-height: 70px;overflow-y:scroll; "></div>
				 </blockquote>
			</div>
			
				 <div class="layui-form-item text-center">
		            <button class="layui-btn layui-btn-primary" onclick="closeDialog('#addFormA')" type="button">取消</button>
		            <button class="layui-btn" lay-filter="addFormSubmit" lay-submit>保存</button>
		        </div>
			
		         </div>
		</form>
    	
    
</div>
<style>
.layui-layer-admin .layui-layer-btn0 {
			background-color: #33aba0;
			border: 1px solid #33aba0;
			color: #FFF;
		}
</style>

<script>
layui.use(['layer', 'table', 'form', 'util', 'config', 'admin','laydate','upload'], function () {
	var $ = layui.jquery;
    var layer = layui.layer;
    var table = layui.table;
    var form = layui.form;
    var util = layui.util;
    var config = layui.config;
    var admin = layui.admin;
    var laydate = layui.laydate;
    var upload = layui.upload;
    layui.form.render("select");
    //$("#pfrId").val(JSON.parse(admin.getUser()).username);
    //laydate.render({
     //   elem: '#pfTime', //指定元素
    //    type: 'datetime'
    //  });
    
    
    var compensation = admin.getTempData('tm_bas_compensation');
    if(compensation!=null){//编辑
    	
    	console.info(compensation);
        //form.val('addForm', compensation);
        $('#addFormA').attr('method', 'post');
        
        $("#formIdA").val(compensation.formId);
    	$("#hiddenIdA").val(compensation.id);
    	$("#orderNoIdA").val(compensation.orderNo);
    	$("#outAmountIdA").val(compensation.outAmount);
    	//$("#pfTime").val(compensation.outTime);
    	//$("#pfrId").val(compensation.outUser);
    	$("#remarkIdA").val(compensation.reason);
    	$("#optCounterIdA").val(compensation.optCounter);
    	
    	$("#outTypeIdA").val(compensation.outType);
    	$("#outAccountIdA").val(compensation.outAccount);
    	
    	//查询已上传的图片
    	 admin.req('w-admin-service/common/attachment/list', {formId:compensation.formId,groupId:'compensation_pic'}, function (data) {
    		 
    		 if(data.success && data.object!=null){
    			 
    			 for(var i = 0;i<data.object.length;i++){
    				 var obj = data.object[i];
    				 var result = '/w-admin-service/common/attachment/download?id='+obj.id;
        			 var s = $("<div style='float:left;border:1px solid;margin-left:5px;margin-bottom:5px;'></div>");
        	        	var img = $("<div></div>")
        	        	img.append('<img src="'+ result +'" height=70 alt="'+ obj.fileName +'" class="layui-upload-img">');
        	          	s.append(img);
        	          //	s.append(toolbar);
        	          	$('#upload_picsIdA').append(s);
        	          	 $("#upload_picsIdA").append("<input type='hidden' name='attsId'  value="+obj.id+" />")
        		 }
    		 }
    		 
    		 
    	 }, 'post');
    	
    	 admin.req('w-admin-service/biz/supplier/allList', {}, function (data) {
    	    	$.each(data, function (index, item) {
    	    		$('#supplierCombA').append(new Option(item.name, item.id));// 下拉菜单里添加元素
    	    	});
    	    	$("#supplierCombA").val(compensation.supplierId);
    	    	layui.form.render("select");
    	 }, 'post');
    	  
    	    admin.req('w-admin-service/biz/platform/queryAll', {}, function (data) {
    	    	$.each(data, function (index, item) {
    	    		$('#platformCombA').append(new Option(item.name, item.id));// 下拉菜单里添加元素
    	    	});
    	    	$("#platformCombA").val(compensation.platformId);
    	    	layui.form.render("select");
    	    }, 'post');
    	
    }else{
    	
    	 admin.req('w-admin-service/common/uuid/generate', {}, function (data) {
    		 $("#formIdA").val(data.object);
    		 
    	 }, 'post');
    	
    	 admin.req('w-admin-service/biz/supplier/allList', {}, function (data) {
 	    	$.each(data, function (index, item) {
 	    		$('#supplierCombA').append(new Option(item.name, item.id));// 下拉菜单里添加元素
 	    	});
 	    	layui.form.render("select");
 	 }, 'post');
 	  
 	    admin.req('w-admin-service/biz/platform/queryAll', {}, function (data) {
 	    	$.each(data, function (index, item) {
 	    		$('#platformCombA').append(new Option(item.name, item.id));// 下拉菜单里添加元素
 	    	});
 	    	layui.form.render("select");
 	    }, 'post');
    }
    
    
  //多图片上传
    upload.render({
      elem: '#upload_picIdA'
      ,url: '/w-admin-service/common/attachment/upload'
      ,multiple: true
      ,before: function(obj){
        //预读本地文件示例，不支持ie8
        obj.preview(function(index, file, result){
        	
        	var s = $("<div style='float:left;border:1px solid;margin-left:5px;margin-bottom:5px;'></div>");
        	var img = $("<div></div>")
        	var imgObj = $('<img src="'+ result +'" height=70 alt="'+ file.name +'" class="layui-upload-img">');
        	$(imgObj).bind("click",{index:index,img:imgObj,result:result},yltupian);
        	img.append(imgObj);
          	s.append(img);
          	
          //	s.append(toolbar);
          	$('#upload_picsIdA').append(s);
          	
        	//$('#upload_picIdA').append('<img src="'+ result +'" style="border:1px solid;" height=70 alt="'+ file.name +'" class="layui-upload-img">&nbsp;&nbsp;')
        });
      }
      ,done: function(res){
        //上传完毕
        
    	  if(res.success){
         	 $("#upload_picsIdA").append("<input type='hidden' name='attsId'  value="+res.object.id+" />")
         }else{
         	 layer.msg(res.message, {icon: 2});
         }
      }
    });
  
  
  
    function yltupian(event){
		var imgObj=event.data.img;
		var result = event.data.result;
		var img = new Image();  
          img.src = imgObj.src;
          var height = imgObj.height + 50; //获取图片高度
          var width = imgObj.width; //获取图片宽度
          var imgHtml = "<img src='" + result + "' style='max-height:580px'/>";  
          //弹出层
          layer.open({  
              type: 1,  
              shade: 0.8,
              offset: '10px',
              area: [width + 'px',height+'px'],
              shadeClose:true,//点击外围关闭弹窗
              scrollbar: false,//不现实滚动条
              title: "图片预览", //不显示标题  
              content: imgHtml, //捕获的元素，注意：最好该指定的元素要存放在body最外层，否则可能被其它的相对元素所影响  
              cancel: function () {  
                  //layer.msg('捕获就是从页面已经存在的元素上，包裹layer的结构', { time: 5000, icon: 6 });  
              }  
          }); 
	}
  
  	
    form.on('submit(addFormSubmit)', function (data) {
        
    	layer.load(2);
        
         var url = "add";
         if($("#hiddenIdA").val()!=null && $("#hiddenIdA").val()!=""){
         	url = "update";
         }
         
         var ids = new Array(); 
         $('input[name="attsId"]').each(function(){
        	 ids.push($(this).val());
         });
         data.field.attId=ids;
        admin.req('w-admin-service/biz/compensation/'+url, data.field, function (data) {
            layer.closeAll('loading');
            if (data.success) {
                layer.msg('保存成功', {icon: 1});
                table.reload('compensationTable');
                admin.closeDialog('#addFormA');
            } else {
                layer.msg(data.message, {icon: 2});
            }
        }, 'post');
        
        return false;
    });
  
    
    
    
    $("#cleanPicsA").click(function(){
    	$("#upload_picsIdA").html("");
    });
    
  	
   
});

</script>